package com.example.expinterview.controller;

import com.example.expinterview.entity.EiRecord;
import com.example.expinterview.entity.ResultBody;
import com.example.expinterview.service.IEiRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @classname: RecordController
 * @description: TODO
 * @author: kaiser
 * @date: 2021/10/20 16:15
 * @version: 1.0
 */
@RestController
@RequestMapping("/record")
@Api(tags = "记录")
public class RecordController {
    private final IEiRecordService service;

    @Autowired
    public RecordController(IEiRecordService service) {
        this.service = service;
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "创建或修改记录")
    public ResultBody save(@RequestBody EiRecord record) {
        return ResultBody.status(service.saveOrUpdate(record));
    }

    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据id获取")
    public ResultBody getById(@PathVariable Long id) {
        return ResultBody.success(service.getById(id));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    public ResultBody delete(@PathVariable Long id) {
        return ResultBody.status(service.removeById(id));
    }
}
